package curso.maven.prototipos.prototipoweb.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.Manifest;

public class LeitorManifest {
	public Manifest ler(URL urlManifest) {
		InputStream streamManifest = abrirStream(urlManifest);
		try {
			return new Manifest(streamManifest);
		} catch (IOException e) {
			throw new RuntimeException("Erro ao abrir manifest de URL: " + urlManifest, e);
		} finally {
			fecharStream(streamManifest);
		}
	}
	
	private InputStream abrirStream(URL url) {
		try {
			return url.openStream();
		} catch (IOException e) {
			throw new RuntimeException("Erro ao abrir URL: " + url, e);
		}
	}
	
	private void fecharStream(InputStream stream) {
		try {
			stream.close();
		} catch (IOException e) {
			throw new RuntimeException("Erro ao fechar stream", e);
		}
	}
}
